page.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { notFound } from "next/navigation";
  2. import { ReaderView } from "@/components/reader/reader-view";
  3. import { getBookById } from "@/data/demo-books";
  4. type ReaderPageProps = {
  5. params: Promise<{
  6. bookId: string;
  7. }>;
  8. searchParams?: Promise<{
  9. chapter?: string;
  10. width?: string;
  11. theme?: string;
  12. font?: string;
  13. }>;
  14. };
  15. export default async function ReaderPage({ params, searchParams }: ReaderPageProps) {
  16. const { bookId } = await params;
  17. const resolvedSearchParams = searchParams ? await searchParams : undefined;
  18. const book = getBookById(bookId);
  19. if (!book) {
  20. notFound();
  21. }
  22. const rawChapterIndex = Number(resolvedSearchParams?.chapter ?? "0");
  23. const chapterIndex =
  24. Number.isFinite(rawChapterIndex) && rawChapterIndex >= 0 && rawChapterIndex < book.chapters.length
  25. ? rawChapterIndex
  26. : 0;
  27. return (
  28. <ReaderView
  29. book={book}
  30. chapterIndex={chapterIndex}
  31. initialWidthKey={resolvedSearchParams?.width}
  32. initialThemeKey={resolvedSearchParams?.theme}
  33. initialFontKey={resolvedSearchParams?.font}
  34. />
  35. );
  36. }